// sharing/pages/status/status.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
	 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	//获取已连接wifi
	  var that = this;

    wx.getStorage({
      key: 'appcolor',
      success: function (res) {
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: res.data,
        })
        that.setData({ 'appColor': res.data });
      },
    })

      wx.getConnectedWifi({
    	  success: function(res){
    		  if(res.errCode==0 || res.errMsg == 'getConnectedWifi:ok'){
    			  app.util.request({
    		          url: 'entry/wxapp/advPic',
    		          data: { BSSID: res.wifi.BSSID, m: 'junsion_wifinav'},
    		          success: function (res) {
    		        	  //广告图
    		        	  if(res.data.img){
    		        		  wx.previewImage({
    		        			  urls: [res.data.img],
    		        		  });
                      wx.getSystemInfo({
                        success: function(s) {
                          that.setData({ img: res.data.img, imgH: s.windowWidth/res.data.width * res.data.height * 2});
                        },
                      })
                      if (res.data.appid) that.setData({appid:res.data.appid,path:res.data.path});
    		        	  }else if(res.data.appid){
                      wx.navigateToMiniProgram({
                         appId: res.data.appid,
                         path: res.data.path,
                      });
                    }else if(res.data.path){
                      wx.setStorageSync('advurl', res.data.path);
                      wx.navigateTo({
                        url: '../webview/webview',
                      });
                    }
    		          }
    		        });
    			  that.setData({wifi:res.wifi});
    		  }else{
    			  that.setData({wifi:false});
    		  }
    	  }
      });
  },

  qitaBtn: function () {
	  wx.switchTab({url: '../applet/applet'});
  },
  onImg : function(){
    var that = this;
    if(that.data.appid){
      wx.navigateToMiniProgram({
        appId: that.data.appid,
        path: that.data.path,
      });
    }else if(that.data.path){
      wx.setStorageSync('advurl', that.data.path);
      wx.navigateTo({
        url: '../webview/webview',
      });
    }else{
      wx.previewImage({
        urls: [that.data.img],
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
	var that = this;
    return {
      title: 'WIFI一键连',
      path: '/sharing/pages/frame/frame',
      success: function(res) {
        // 转发成功
      },
      fail: function(res) {
        // 转发失败
      }
    }
  }
})